package sg.edu.nus.iss.vmcs.interfaces;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

import sg.edu.nus.iss.vmcs.system.SimulationController;
import sg.edu.nus.iss.vmcs.system.VMCSControlUI;

public class SWTSimulatorPanel implements VMCSControlUI{
	
	private Shell shell;
	private Display display;
	private SimulationController controller;
	private Button beginSimulation;
	private Button activateCustomer;
	private Button activateMaintenance;
	private Button activateMachinary;
	
	public SWTSimulatorPanel(SimulationController controller) {
		this.controller = controller;
		display = new Display();
        shell = new Shell(display);
        RowLayout layout = new RowLayout();
        layout.wrap = true;
        shell.setLayout(layout);
        shell.setText("VMCS using SWT Abstract Factory with Command/Adapter implementation");
        initialize();
       
    }
	
	public Shell getShell() {
		return shell;
	}
	private void initialize(){
		 // Create the children of the composite.
        beginSimulation = new Button(shell, SWT.PUSH);
        beginSimulation.setText("Begin Simulation");
        activateCustomer = new Button(shell, SWT.PUSH);
        activateCustomer.setText("Activate Customer Panel");
        activateCustomer.addListener(ACT_CUSTOMER, new Listener() {
			
			@Override
			public void handleEvent(Event event) {
				controller.setupCustomer();
			}
		});
        activateMaintenance = new Button(shell, SWT.PUSH);
        activateMaintenance.setText("Activate Maintenance Panel");
        activateMachinary = new Button(shell, SWT.PUSH);
        activateMachinary.setText("Activate Machinary Panel");
        shell.pack();
	}

	@Override
	public void display() {
		   shell.open();
		   while (!shell.isDisposed()) {
	            if (!display.readAndDispatch()) display.sleep();
	        }
	}

	@Override
	public void setSimulationActive(boolean isOn) {
		
	}

	@Override
	public void setButtonState(int id, boolean state) {
		
	}

	@Override
	public void stop() {
	}

	@Override
	public void closeDown() {
	}

	@Override
	public void setActive(int id, boolean state) {
	}
}
